#include <stdio.h>
#include "FileUtils.cuh"

int number_of_lines(char* file)
{

	FILE* myfile = fopen(file, "r");
	int ch, number_of_lines = 0;

	do
	{
		ch = fgetc(myfile);
		if(ch == '\n')
			number_of_lines++;
	} while (ch != EOF);

	// last line doesn't end with a new line!
	// but there has to be a line at least before the last line
	if(ch != '\n' && number_of_lines != 0)
		number_of_lines++;

	fclose(myfile);

	return number_of_lines;

}

bool file_exists(const char * filename)
{
    if (FILE * file = fopen(filename, "r"))
    {
        fclose(file);
        return true;
    }
    return false;
}
